home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / Snippets / QuickDraw / Compressed PICT Info / Compressed PICT Info.c next >
Encoding:
C/C++ Source or Header  |  1992-11-16  |  6.3 KB  |  269 lines  |  [TEXT/KAHL]

  1. /****************************************************************************/
  2. /*                                                                            */
  3. /*    Application:    Compressed PICT Info                                    */
  4. /*                                                                            */
  5. /*    Description:    This snippet shows how to use the StdPix proc to        */
  6. /*                    intercept and display the compression type and depth    */
  7. /*                    of any compressed PICT within a PICT resource.  The        */
  8. /*                    same procedure can be used to gather other information    */
  9. /*                    about the compressed PICT.  Note that all compressed    */
  10. /*                    PICTs get passed into StdPix before getting decom-        */
  11. /*                    pressed and passed to StdBits.                            */
  12. /*                                                                            */
  13. /*    Files:            Compressed PICT Info.π                                    */
  14. /*                    Compressed PICT Info.π.rsrc                                */
  15. /*                    Compressed PICT Info.c                                    */
  16. /*                                                                            */
  17. /*    Programmer:        Edgar Lee                                                */
  18. /*    Organization:    Apple Computer, Inc.                                    */
  19. /*    Department:        Developer Technical Support, DTS                        */
  20. /*    Language:        C (Think C version 5.0.2)                                */
  21. /*    Date Created:    10-20-92                                                */
  22. /*                                                                            */
  23. /****************************************************************************/
  24.  
  25. #include <ImageCompression.h>
  26. #include <Movies.h>
  27.  
  28. /* Constant Declarations */
  29.  
  30. #define    WWIDTH    170
  31. #define    WHEIGHT    220
  32.  
  33. #define WLEFT    (((screenBits.bounds.right - screenBits.bounds.left) - WWIDTH) / 2)
  34. #define WTOP    (((screenBits.bounds.bottom - screenBits.bounds.top) - WHEIGHT) / 2)
  35.  
  36. /* Global Variable Definitions */
  37.  
  38. CodecType    gCodec = 'unkn';
  39. int            gDepth;
  40.  
  41. void initMac();
  42. void checkForQuickTime();
  43.  
  44. void createWindow();
  45. void doEventLoop();
  46.  
  47. void doBottleneckTest();
  48.  
  49. main()
  50. {
  51.     initMac();
  52.     checkForQuickTime();
  53.     
  54.     createWindow();
  55.     doEventLoop();
  56. }
  57.  
  58. void initMac()
  59. {
  60.     MaxApplZone();
  61.  
  62.     InitGraf( &thePort );
  63.     InitFonts();
  64.     InitWindows();
  65.     InitMenus();
  66.     TEInit();
  67.     InitDialogs( nil );
  68.     InitCursor();
  69.     FlushEvents( 0, everyEvent );
  70. }
  71.  
  72. void checkForQuickTime()
  73. {
  74.     long    version;
  75.     
  76.     if (Gestalt( gestaltQuickTime, &version ) != noErr)
  77.     {
  78.         ParamText( "\pQuickTime not installed.  Please install, then try again.", "\p", "\p", "\p" );
  79.         Alert( 128, nil );
  80.         ExitToShell();
  81.     }
  82. }
  83.  
  84. void createWindow()
  85. {
  86.     Rect        rect;
  87.     WindowPtr    window;
  88.     
  89.     SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
  90.     window = NewCWindow( 0L, &rect, "\pStdPix", true, documentProc,
  91.                             (WindowPtr)-1L, true, 0L );                        
  92.     SetPort( window );
  93.     
  94.     TextMode( srcCopy );
  95.     TextSize( 9 );
  96.     TextFont( geneva );
  97. }
  98.  
  99. pascal void myStdPix( PixMapPtr src, Rect *srcRect, MatrixRecordPtr matrix,
  100.                         short mode, RgnHandle mask, PixMapPtr matte,
  101.                         Rect *matteRect, short flags )
  102. {
  103.     ImageDescriptionHandle        desc;
  104.     Ptr                            data;
  105.     long                        bufferSize;
  106.     
  107.     GetCompressedPixMapInfo( src, &desc, &data, &bufferSize, nil, nil );
  108.     gCodec = (**desc).cType;
  109.     gDepth = (**desc).depth;
  110. }
  111.  
  112. pascal void myTextProc( short byteCount, Ptr textBuf, Point numer, Point denom )
  113. {
  114. }
  115.  
  116. pascal void myLineProc( Point newPt )
  117. {
  118. }
  119.  
  120. pascal void myRectProc( GrafVerb verb, Rect *r )
  121. {
  122. }
  123.  
  124. pascal void myRRectProc( GrafVerb verb, Rect *r, short ovalWidth, short ovalHeight )
  125. {
  126. }
  127.  
  128. pascal void myOvalProc( GrafVerb verb, Rect *r )
  129. {
  130. }
  131.  
  132. pascal void myArcProc( GrafVerb verb, Rect *r, short startAngle, short arcAngle )
  133. {
  134. }
  135.  
  136. pascal void myPolyProc( GrafVerb verb, PolyHandle poly )
  137. {
  138. }
  139.  
  140. pascal void myRgnProc( GrafVerb verb, RgnHandle rgn )
  141. {
  142. }
  143.  
  144. pascal void myBitsProc( BitMap *bitPtr, Rect *srcRect, Rect *dstRect,
  145.                         short mode, RgnHandle maskRgn )
  146. {
  147. }
  148.  
  149. void DrawCompressionType( CodecType    codec, int col, int row )
  150. {
  151.     MoveTo(    col, row );
  152.     
  153.     if (codec == 'rpza')
  154.         DrawString( "\pVideo Compression" );
  155.     else if (codec == 'jpeg')
  156.         DrawString( "\pJPEG Compression" );
  157.     else if (codec == 'rle ')
  158.         DrawString( "\pAnimation Compression" );
  159.     else if (codec == 'raw ')
  160.         DrawString( "\pRaw Compression" );
  161.     else if (codec == 'smc ')
  162.         DrawString( "\pGraphics Compression" );
  163.     else
  164.         DrawString( "\pUnknown Compression" );
  165. }
  166.  
  167. void DrawCompressionDepth( int depth, int col, int row )
  168. {
  169.     Str255    string;
  170.     
  171.     NumToString( (long)depth, string );
  172.     
  173.     MoveTo(    col, row );
  174.     DrawString( "\pImage Depth:" );
  175.     
  176.     MoveTo(    col + 70, row );
  177.     DrawString( string );
  178. }
  179.  
  180. void doBottleneckTest()
  181. {
  182.     int            i;
  183.     PicHandle    picture;
  184.     Rect        rect;
  185.     CQDProcs    bottlenecks;
  186.  
  187.     /* Define our own bottlenecks to do nothing. */
  188.     SetStdCProcs( &bottlenecks );
  189.     
  190.     bottlenecks.textProc    = (Ptr)myTextProc;
  191.     bottlenecks.lineProc    = (Ptr)myLineProc;
  192.     bottlenecks.rectProc    = (Ptr)myRectProc;
  193.     bottlenecks.rRectProc    = (Ptr)myRRectProc;
  194.     bottlenecks.ovalProc    = (Ptr)myOvalProc;
  195.     bottlenecks.arcProc        = (Ptr)myArcProc;
  196.     bottlenecks.polyProc    = (Ptr)myPolyProc;
  197.     bottlenecks.rgnProc        = (Ptr)myRgnProc;
  198.     bottlenecks.bitsProc    = (Ptr)myBitsProc;
  199.     bottlenecks.newProc1    = (Ptr)myStdPix;        /* pixProc */
  200.     
  201.     for (i = 0; i < Count1Resources( 'PICT' ); i++)
  202.     {
  203.         /* Load & draw pictures from resource. */
  204.         picture = (PicHandle)Get1IndResource( 'PICT', i + 1 );
  205.         
  206.         rect = (**picture).picFrame;
  207.         OffsetRect( &rect, -rect.left, -rect.top );
  208.         OffsetRect( &rect, 10, ((rect.bottom - rect.top) + 10) * i + 10 );
  209.                 
  210.         DrawPicture( picture, &rect );
  211.         
  212.         /* Install our custom bottlenecks to intercept any compressed images. */
  213.         (*(qd.thePort)).grafProcs = (QDProcs *)&bottlenecks;
  214.          DrawPicture( picture, &((**picture).picFrame) );
  215.          
  216.         /* Switch back to the default procs. */
  217.           (*(qd.thePort)).grafProcs = 0L;
  218.      
  219.         /* Free any memory used by the picture. */
  220.         ReleaseResource( picture );
  221.         
  222.         /* Display the compression type. */
  223.         DrawCompressionType( gCodec, rect.right + 10, rect.top + 10 );
  224.         DrawCompressionDepth( gDepth, rect.right + 10, rect.top + 25 );
  225.         gCodec = 'unkn';
  226.     }
  227. }
  228.  
  229. void doEventLoop()
  230. {
  231.     EventRecord event;
  232.     WindowPtr   window;
  233.     short       clickArea;
  234.     Rect        screenRect;
  235.  
  236.     for (;;)
  237.     {
  238.         if (WaitNextEvent( everyEvent, &event, 0, nil ))
  239.         {
  240.             if (event.what == mouseDown)
  241.             {
  242.                 clickArea = FindWindow( event.where, &window );
  243.                 
  244.                 if (clickArea == inDrag)
  245.                 {
  246.                     screenRect = (**GetGrayRgn()).rgnBBox;
  247.                     DragWindow( window, event.where, &screenRect );
  248.                 }
  249.                 else if (clickArea == inContent)
  250.                 {
  251.                     if (window != FrontWindow())
  252.                         SelectWindow( window );
  253.                 }
  254.                 else if (clickArea == inGoAway)
  255.                     if (TrackGoAway( window, event.where ))
  256.                         return;
  257.             }
  258.             else if (event.what == updateEvt)
  259.             {
  260.                 window = (WindowPtr)event.message;    
  261.                 SetPort( window );
  262.                 
  263.                 BeginUpdate( window );
  264.                 doBottleneckTest();
  265.                 EndUpdate( window );
  266.             }
  267.         }
  268.     }
  269. }